package com.atguigu.lease.common.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author hzq
 * @version 1.0
 * @description:
 * @date 2024/8/12 14:31
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        //自动填充添加时间的属性值
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
      // 自动填充(是否删除)删除状态的属性值
        this.strictInsertFill(metaObject, "isDeleted", Byte.class, (byte) 0);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //自动填充更新时间的属性值
        this.strictInsertFill(metaObject, "updateTime", Date.class, new Date());
    }
}
